<template>
    <div>
        <h1>康复理疗新增</h1>
        <table class="table table-bordered">
            <tbody>
                <tr>
                    <td align="right">项目名称</td>
                    <td><input type="text" v-model="info.dname"></td>
                </tr>
                <tr>
                    <td align="right">项目编码</td>
                    <td>
                    <td><input type="text" v-model="info.dbm" disabled></td>
                    </td>
                </tr>
                <tr>
                    <td align="right">佣金</td>
                    <td>
                    <td><input type="text" v-model="info.dmoney">元</td>
                    </td>
                </tr>
                <tr>
                    <td align="right">服务人数</td>
                    <td>
                    <td><input type="text" v-model="info.dnum">人</td>
                    </td>
                </tr>
                <tr>
                    <td align="right">服务时长</td>
                    <td>
                    <td><input type="text" v-model="info.dtime">小时</td>
                    </td>
                </tr>
                <tr>
                    <td align="right">项目说明</td>
                    <td>
                        <textarea cols="20" rows="5" v-model="info.dsm"></textarea>
                    </td>
                </tr>
                <tr>
                    <td align="right">状态</td>
                    <td>
                        <input type="radio" name="a" :value="1" v-model="info.dzt">启用
                        <input type="radio" name="a" :value="0" v-model="info.dzt">禁用
                    </td>
                </tr>
                <tr>
                    <td align="right"></td>
                    <td><input type="button" class="btn btn-primary" value="新增" @click="add"></td>
                </tr>

            </tbody>
        </table>

    </div>
</template>

<script setup lang="ts">

import axios from 'axios'
import { ref, reactive, onMounted } from 'vue'
import moment from 'moment'
import 'bootstrap/dist/css/bootstrap.css'
import { useRouter, useRoute } from 'vue-router'
const router = useRouter();
const route = useRoute();

let info: any = reactive({
    "dname": "",
    "dbm": moment(new Date()).format("yyyyMMdd")+Math.random().toString().substring(3,5),
    "dmoney": '',
    "dnum": '',
    "dtime": '',
    "dsm": "",
    "dzt": 1,
})

const add = () => {
    if (info.dname == '') {
        alert('项目名称不能为空');
        return;
    }
    if (info.dmoney == '') {
        alert('佣金不能为空');
        return;
    }
    if (info.dnum == '') {
        alert('服务人数不能为空');
        return;
    }
    var a='^\+?[1-9][0-9]*$';
    if (info.dnum.test(a)) {
        alert('服务人数必须是整数');
        return;
    }
    if (info.dtime == '') {
        alert('服务时长不能为空');
        return;
    }
    if (!info.dtime.test(a)) {
        alert('服务时长必须是整数');
        return;
    }
    if (info.dsm == '') {
        alert('项目说明不能为空');
        return;
    }
    axios({
        url: '/api/Doctor/AddDoctor',
        method: 'post',
        data: info
    })
        .then(res => {
            console.log(res);
            if (res.data > 0) {
                alert('新增成功');
                router.push('/doctorshow')
            }
            else {
                alert('新增失败');
                return;
            }
        })
}



</script>

<style scoped></style>